package 集合框架;

import org.junit.Test;
import 包装数据类型.Student;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class CollectionDemo {
    @Test
    public void test1(){
        ArrayList<Student> list = new ArrayList();
        Student student1 = new Student(1);
        Student student2 = new Student(2);
        Student student3 = new Student(3);
        list.add(student1);
        list.add(student2);
        list.add(student3);

        for(Student student:list){
            System.out.println(student);
        }
//        Student{id=1, name='null', grade=null}
//        Student{id=2, name='null', grade=null}
//        Student{id=3, name='null', grade=null}
    }

    @Test
    public void test2(){
        HashMap<String,String> map = new HashMap<>();
        map.put("cn","中国");
        map.put("us","美国");
        map.put("uk","英国");
        //遍历HashMmap 的一种方式
        Set<Map.Entry<String,String>> set = map.entrySet();
        for(Map.Entry<String,String> entry : set){
            System.out.println(entry.getKey()+" : "+entry.getValue());
        }

        System.out.println("--------------");
        //又一种方式
        Set<String> set1 = map.keySet();
        for (String key : set1) {
            System.out.println(key+" : "+map.get(key));
        }
    }
}
